<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/8/8
  Time: 20:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <base href="${pageContext.request.contextPath}/">
    <title>添加机房信息</title>
    <script src="jq/jquery.js"></script>
</head>
<body>
    <p style="font-size: 20px">添加机房信息页面</p>
    <form action="ComputerRoomAdd" method="post">
        <p>机房名称：<input type="text" id="roomName" name="roomName"></p>
        <p>计算机数量：<input type="text" id="computerNumber" name="computerNumber"></p>
        <p>机房管理员：<input type="text" id="manager" name="manager"></p>
        <p>机房地址：<input type="text" id="location" name="location"></p>
        <p>
            机房状态：
            <select name="state" id="state">
                <option selected>--请选择--</option>
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
            </select>
        </p>
        <p>相关操作：<input type="submit" value="新增"> <input type="button" value="重置" onclick="reset()"></p>
    </form>
</body>
<script>
    function reset() {
        $("#roomName").val("");
        $("#computerNumber").val("");
        $("#manager").val("");
        $("#location").val("");
        $("#state").index(0);
    }

    //单击“提交”按钮提交表单
    $('form').submit(function(){
        var flag=true;
        if(!CheckName()) flag=false;
        else if(!CheckNumber()) flag=false;
        else if(!CheckManager()) flag=false;
        else if(!CheckLocation()) flag=false;
        else if(!CheckState()) flag=false;
        return flag;
    })

    function CheckName(){
        var name=$('#roomName').val();
        if(name==""){
            alert("机房名称不能为空")
            return false;
        }
        return true;
    }

    function CheckNumber() {
        var number = $('#computerNumber').val();
        if(number == ""){
            alert("计算机数量不能为空")
            return false;
        }else if(isNaN(parseInt(number)) || parseInt(number) < 1){
            alert("计算机数量必须大于0整数")
            return false;
        }
        return true;
    }

    function CheckManager() {
        var manager = $('#manager').val();
        if (manager == "") {
            alert("机房管理员不能为空")
            return false;
        }
        return true;
    }

    function CheckLocation() {
        var location = $('#location').val();
        if(location == ""){
            alert("机房地址不能为空")
            return false;
        }
        return true;
    }

    function CheckState() {
        var state = $('#state');
        if(state.get(0).selectedIndex==0){
            alert("请选择机房的状态")
            return false;
        }
        return true;
    }
</script>
</html>
